<?php

/**
 * This is the model class for table "zy_application".
 *
 * The followings are the available columns in table 'zy_application':
 * @property integer $application_id
 * @property string $application_name
 * @property string $platform
 * @property string $application_server_key
 * @property integer $usercount
 */
class Application extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Application the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'zy_application';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('usercount', 'numerical', 'integerOnly'=>true),
			array('application_name, platform, application_server_key,pem_file,pem_password', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('application_id, application_name, platform, application_server_key,pem_file,pem_password, usercount', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'application_id' => Yii::t('base','Application'),
			'application_name' => Yii::t('base','Application Name'),
			'platform' => Yii::t('base','Platform'),
			'application_server_key' => Yii::t('base','Application Server Key'),
			'pem_file' => Yii::t('base','Pem File'),
			'pem_password' => Yii::t('base','Pem Password'),
			'usercount' => Yii::t('base','Usercount'),
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('application_id',$this->application_id);
		$criteria->compare('application_name',$this->application_name,true);
		$criteria->compare('platform',$this->platform,true);
		$criteria->compare('application_server_key',$this->application_server_key,true);
		$criteria->compare('pem_file',$this->pem_file,true);
		$criteria->compare('pem_password',$this->pem_password,true);
		$criteria->compare('usercount',$this->usercount,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	//通过应用的key得到应用的名称
	/**
	 *  1=netcube dailer
		2=netcube smartrouting
		3=netcube tv
		4=mynetcube
	 * */
	public function getApplicationName($applicationid)
	{
		//$application=Application::model()->findByPk($applicationid);
		$application=array();
		$applicationidarr = str_replace("|", ",", $applicationid);	
		$sql="select * from zy_application where application_id in($applicationidarr)";
		$application_id=Yii::app()->db->createCommand($sql)->queryAll();
		for ($i = 0; $i < count($application_id); $i++) {
			$application[$i] = $application_id[$i]['application_name'];
		}
		$applicationName=implode('|',$application);
		return $applicationName;
	}
	//输出平台
	/**
	 * 0表示android,1表示ios
	 */
	 public function getplatformName($platform)
	 {
	 	if($platform=='0')
	 	$platformName="android";
	 	if($platform=='1')
	 	$platformName="ios";
	 	if($platform=='2')
	 	$platformName="android|ios";
	 	return $platformName;
	 }
}